@extends('admin.layouts')
@section('css')
    <link href="{{asset('assets/css/bootstrap.min.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{asset('assets/css/font-awesome.min.css')}}" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

    <!-- ace styles -->

    <link rel="stylesheet" href="{{asset('assets/css/ace.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-rtl.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-skins.min.css')}}" />
    <script src="{{asset('assets/js/ace-extra.min.js')}}"></script>

    {{--时间样式--}}
    <link rel="stylesheet" href="{{asset('assets/css/datepicker.css')}}" />

    <style>
        .cover{
            border: 1px solid #AAA;
            padding: 2px;
            background-color: #FFF;
        }
        .pagination{margin: -13px 0 -13px 30px;}
    </style>
@endsection
@section('content')
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{{url('admin/index')}}">主页</a>
                </li>

                <li>
                    <a>文章</a>
                </li>
                <li class="active">
                        文章回收站

                </li>
            </ul><!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
                </form>
            </div><!-- #nav-search -->
        </div>

        <div class="page-content">
            <div class="page-header">
                <h1>
                    文章管理
                    <small>
                        <i class="icon-double-angle-right"></i>
                            文章回收站
                    </small>
                </h1>
            </div><!-- /.page-header -->

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <form action="" method="post">
                        <div class="col-md-3 col-xs-12">
                                <div class="input-group">
                                    <input class="form-control date-picker" value="{{$startTime}}" name="start_time" placeholder="开始创建时间" id="id-date-picker-1" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                                </div>
                        </div>
                        {{csrf_field()}}
                        <div class="col-md-3 col-xs-12">
                            <div class="input-group">
                                <input class="form-control date-picker" value="{{$endTime}}" name="end_time" placeholder="结束创建时间" id="id-date-picker-2" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                            </div>
                        </div>
                        <div class="col-md-3 col-xs-12">
                            <div class="input-group">
                                <select name="category_id" id="category_id" class="form-control">
                                    <option value="">==选择文章分类==</option>
                                    @foreach($category as $v)
                                        <option value="{{$v['id']}}"
                                                @if($category_id==$v['id'])
                                                selected=""
                                                @endif
                                        >{{$v['category']}}</option>
                                    @endforeach
                                </select>
                            <span class="input-group-addon">
                                <i class="icon-bookmark-empty bigger-110"></i>
                            </span>
                            </div>
                        </div>

                        <div class="col-md-3 col-xs-12">
                            <div class="input-group">
                                <input type="text" name="title" id="searchTitle" class="form-control search-query" value="{{$titler}}" placeholder="输入文章标题搜索..." />
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-purple btn-sm">
                                        搜索
                                        <i class="icon-search icon-on-right bigger-110"></i>
                                    </button>
                                </span>
                            </div>
                        </div>
                        </form>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            <hr>
                            <form action="{{url('admin/artilelist/0')}}" id="selectedd">
                            <div class="table-responsive">
                                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th class="center">
                                            <label>
                                                <input type="checkbox" class="ace" />
                                                <span class="lbl"></span>
                                            </label>
                                        </th>
                                        <th>ID</th>
                                        <th>分类</th>
                                        <th>标题</th>
                                        <th>封面</th>
                                        <th>Banner图</th>
                                        <th>浏览次数</th>
                                        @if(empty(Session::get('admin')['is_author']))
                                            <th>作者</th>
                                        @endif
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            创建时间
                                        </th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            更新时间
                                        </th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    @if(sizeof($allarticle)>0)
                                    @foreach($allarticle as $v)
                                        <tr id="id{{$v['id']}}">
                                            <td class="center">
                                                <label>
                                                    <input type="checkbox" class="ace" name="selected[{{$v['id']}}]" value="{{$v['id']}}" />
                                                    <span class="lbl"></span>
                                                </label>
                                            </td>
                                            <td>{{$v['id']}}</td>
                                            <td>{{$v['category']}}</td>
                                            <td>{{$v['title']}}</td>
                                            <td>
                                                <span class="btn btn-xs btn-info tooltip-info" data-rel="tooltip" data-placement="top" title="
                                                <img class='cover' src='{{$v['cover']}}-185X141' alt='cover'  height='135px'>
                                                ">查看封面</span>
                                            </td>
                                            <td>
                                                @if(!empty($v['banner']))
                                                <span class="btn btn-xs btn-info tooltip-info" data-rel="tooltip" data-placement="top" title="
                                                <img class='cover' src='{{$v['banner']}}-200X92' alt='cover'  height='85'>
                                                ">查看Banner</span>
                                                    @else
                                                    没有Banner
                                                @endif
                                            </td>
                                            <td>{{$v['views']}}</td>
                                            @if(empty(Session::get('admin')['is_author']))
                                                <td>
                                                    @if(!empty($v['username']))
                                                        {{$v['username']}}
                                                    @else
                                                        管理员
                                                    @endif
                                                </td>
                                            @endif
                                            <td>{{date('Y-m-d H:i:s',$v['created_at'])}}</td>
                                            <td>{{date('Y-m-d H:i:s',$v['updated_at'])}}</td>

                                            <td>
                                                <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
                                                    <a class="btn btn-xs btn-info"  onclick="dupdateStatus({{$v['id']}},{{$v['status']}})" data-rel="tooltip" data-placement="top" title="恢复文章">
                                                        <i class="icon-reply bigger-120"></i>
                                                    </a>

                                                    <a class="btn btn-xs btn-danger" onclick="deletea({{$v['id']}})" data-rel="tooltip" data-placement="top" title="删除文章">
                                                        <i class="icon-remove bigger-120"></i>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                        @else
                                        <tr>
                                           <td style="text-align: center" colspan="11">什么都没有啦</td>
                                        </tr>
                                    @endif
                                    </tbody>
                                </table>
                            </div><!-- /.table-responsive -->
                                <button class="btn btn-success btn-sm" type="submit">移出回收站</button>
                                <button class="btn btn-danger btn-sm" type="button" id="multiDelete">删除文章</button>
                            {{$allarticle->links()}}
                            </form>
                        </div><!-- /span -->
                    </div><!-- /row -->

                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
@endsection
@section('javascript')
    <script src='{{asset('assets/js/jquery-2.0.3.min.js')}}'></script>
    <script src="{{asset('assets/js/bootstrap.min.js')}}"></script>
    <script src="{{asset('assets/js/typeahead-bs2.min.js')}}"></script>

    <!-- ace scripts -->
    <script type="text/javascript" src="{{asset('assets/layer/layer.js')}}"></script>
    <script src="{{asset('assets/js/ace-elements.min.js')}}"></script>
    <script src="{{asset('assets/js/ace.min.js')}}"></script>

    {{--时间插件--}}
    <script src="{{asset('assets/js/date-time/bootstrap-datepicker.min.js')}}"></script>
    <script>
        $('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
            $(this).prev().focus();
        });

        $('[data-rel=tooltip]').tooltip({html:true});

        $('table th input:checkbox').on('click' , function(){
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function(){
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });

        });
    </script>
    <script>
        function deletea(id){
            layer.confirm('你确定要删除吗？',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                layer.load(1);
                $.post('{{url('admin/deletearticle')}}',{'_token':'{{csrf_token()}}','id':id}, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        $("#id"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }

        function dupdateStatus(id,status){
            layer.confirm('你确定要恢复本文章吗？',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                layer.load(1);
                $.post('{{url('admin/updatearticlestatus')}}',{'_token':'{{csrf_token()}}','id':id,'status':status}, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        $("#id"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }

        $("#selectedd").submit(function () {
            layer.confirm('你确定要移出回收站吗？',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                var data=$("#selectedd").serializeArray();
                if(data.length==0){
                    layer.alert('您未选择文章!', {icon: 5});
                    return false;
                }
                layer.load(1);
                var postData={};
                $(data).each(function() {
                    postData[this.name]=this.value;
                });
                $.post('{{url('admin/multiupdatearticlestatus')}}?_token={{csrf_token()}}&status=1',postData, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        layer.msg(res.msg);
                        sleep(2100);
//                        location.reload();
                        location.href="{{url('admin/artilelist/0')}}";
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
            return false;
        });
        $("#multiDelete").click(function () {
            layer.confirm('你确定要删除吗？不可恢复！',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                var data=$("#selectedd").serializeArray();
                if(data.length==0){
                    layer.alert('您未选择文章!', {icon: 5});
                    return false;
                }
                layer.load(1);
                var postData={};
                $(data).each(function() {
                    postData[this.name]=this.value;
                });
                $.post('{{url('admin/multideletearticle')}}?_token={{csrf_token()}}',postData, function (res) {
                    layer.closeAll('loading');
//                    console.log(res.msg);
                    if(res.status){
                        layer.msg(res.msg);
                        sleep(2100);
                        location.href="{{url('admin/artilelist/0')}}";
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        });

        function sleep(numberMillis) {
            var now = new Date();
            var exitTime = now.getTime() + numberMillis;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    return;
            }
        }
    </script>
@endsection